package com.cntaiping.ttnews;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.cntaiping.ttnews.adapter.VpAdapter;
import com.cntaiping.ttnews.fragment.NewsFragment;
import com.cntaiping.ttnews.fragment.VideoFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    //https://git.oschina.net/renbeyond/TTNews
    ImageView ivUser;
    TabLayout tabLayout;
    ViewPager viewPager;
    private List<Fragment> fragmentList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ivUser = (ImageView) findViewById(R.id.iv_user);
        tabLayout = (TabLayout) findViewById(R.id.tab_main);
        viewPager = (ViewPager) findViewById(R.id.vp_main);
        fragmentList = new ArrayList<>();
        initUI();
        viewPager.setAdapter(new VpAdapter(getSupportFragmentManager() , fragmentList));
        tabLayout.setupWithViewPager(viewPager);
        //初始化主界面
    }

    private void initUI() {
        fragmentList.add(new NewsFragment().newInstacnce("快报"));
        fragmentList.add(new VideoFragment());
        fragmentList.add(new NewsFragment().newInstacnce("直播"));
        fragmentList.add(new NewsFragment().newInstacnce("娱乐"));
        fragmentList.add(new NewsFragment().newInstacnce("社会"));
    }


}
